import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_ytx_plugin/src/flutter_ytx_plugin.dart';
import 'package:flutter_ytx_plugin/src/utils/screen_utils.dart';

import 'contactInfo.dart';
import 'dart:io';

class ContactsWidget {
  static Widget getSusItem(BuildContext context, String tag,
      {double susHeight = 40, double? fontSize, double ? desfontsize}) {
    if (tag == '✩') {
      tag = '✩ 星标数字人';
    }
    if (tag == '') {
      tag = '我的数字人';
    }
    return Container(
      height: susHeight,
      width: MediaQuery
          .of(context)
          .size
          .width,
      padding: EdgeInsets.only(left: 16.0
        ..wpx),
      color: const Color(0xFFF6FAFE),
      //const Color(0XFF171A21),
      alignment: Alignment.centerLeft,
      child: Text(
        tag,
        softWrap: false,
        style: TextStyle(
          fontSize: 12.0
            ..tpx,
          color: const Color(0xFF5B5C60),
        ),
      ),
    );
  }

  static Widget getWeChatListItem(BuildContext context, ContactInfo model,
      {double susHeight = 40,
        Color? defHeaderBgColor,
        Function? function,
        double? fontsize,
        double ? desfontsize,
        double spt = 1,
        double sw = 1,
        double sh = 1}) {
    return getWeChatItem(context, model,
        defHeaderBgColor: defHeaderBgColor,
        function: function,
        sh: sh,
        spt: spt,
        sw: sw);
  }

  static Widget getWeChatItem(BuildContext context, ContactInfo model,
      {Color? defHeaderBgColor,
        Function? function,
        double spt = 1,
        double sw = 1,
        double sh = 1}) {
    DecorationImage? image;

    return GestureDetector(
      onTap: () {
        function?.call(model.name);
      },
      child: Container(
        width: 375 * sw,
        color: const Color(0xFFF6FAFE),
        child: Column(
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Container(
                  width: 40 * sw,
                  height: 40 * sw,
                  margin: EdgeInsets.symmetric(
                      vertical: 12 * sw, horizontal: 15 * sw),
                  decoration: BoxDecoration(
                    shape: BoxShape.rectangle,
                    borderRadius: BorderRadius.circular(20 * sw),
                    color: model.gradient == null
                        ? (model.bgColor ?? defHeaderBgColor)
                        : null,
                    image: image,
                    gradient: LinearGradient(
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                      colors:
                      model.gradient ?? [Colors.white, Colors.transparent],
                    ),
                  ),
                  child: model.img != null
                      ? ClipRRect(
                    borderRadius: BorderRadius.circular(20 * sw),
                    clipBehavior: Clip.antiAlias,
                    child: CachedNetworkImage(
                      width: 40 * sw,
                      height: 40 * sw,
                      fit: BoxFit.fill,
                      imageUrl: "${model.img}",
                      placeholder: (context, url) =>
                          Center(
                              child: CircularProgressIndicator(
                                value: null,
                                strokeWidth: 1.0,
                                color: Colors.white.withOpacity(0.8),
                              )),
                      errorWidget: (context, url, error) =>
                          Icon(
                            Icons.account_circle_outlined,
                            color: Colors.white.withOpacity(0.8),
                            size: 40 * sh,
                          ),
                    ),
                  )
                      : model.iconData == null
                      ? const SizedBox()
                      : model.iconData is IconData
                      ? Icon(
                    model.iconData,
                    color: Colors.white,
                    size: 17 * spt,
                  )
                      : Center(
                    child: Image.asset(model.iconData,
                        width: 17 * sw, height: 17 * sw),
                  ),
                ),
                Container(
                  height: 50 * sw,
                  alignment: Alignment.centerLeft,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        model.name,
                        style: TextStyle(
                            fontSize: 15 * spt,
                            color: Colors.black,
                            fontWeight: Platform.isIOS
                                ? FontWeight.w600
                                : FontWeight.w500),
                      ),
                      if (model.subtitle != null && model.subtitle != null)
                        Text(
                          model.subtitle ?? '',
                          style: TextStyle(
                              color: const Color(0Xff5B5C60),
                              fontSize: 12 * spt),
                        )
                    ],
                  ),
                )
              ],
            ),
            Container(
              width: 375 * sw,
              margin: EdgeInsets.only(left: 70 * sw),
              decoration: BoxDecoration(
                border: Border(
                  bottom: BorderSide(
                    color: const Color.fromRGBO(0, 0, 0, 0.05),
                    width: 1 * sh,
                  ),
                ),
              ),
            )
          ],
        ),
      ),
    );
    // return ListTile(
    //   leading: Container(
    //     width: 40 * sw,
    //     height: 40 * sw,
    //     decoration: BoxDecoration(
    //       shape: BoxShape.rectangle,
    //       borderRadius: BorderRadius.circular(20 * sw),
    //       color: model.gradient == null
    //           ? (model.bgColor ?? defHeaderBgColor)
    //           : null,
    //       image: image,
    //       gradient: LinearGradient(
    //         begin: Alignment.centerLeft,
    //         end: Alignment.centerRight,
    //         colors: model.gradient ?? [Colors.white, Colors.transparent],
    //       ),
    //     ),
    //     child: model.img != null
    //         ? ClipRRect(
    //       borderRadius: BorderRadius.circular(20 * sw),
    //       clipBehavior: Clip.antiAlias,
    //       child: CachedNetworkImage(
    //         width: 40 * sw,
    //         height: 40 * sw,
    //         fit: BoxFit.fill,
    //         imageUrl: "${model.img}",
    //         placeholder: (context, url) => Center(
    //             child: CircularProgressIndicator(
    //               value: null,
    //               strokeWidth: 1.0,
    //               color: Colors.white.withOpacity(0.8),
    //             )),
    //         errorWidget: (context, url, error) => Icon(
    //           Icons.account_circle_outlined,
    //           color: Colors.white.withOpacity(0.8),
    //           size: 40 * sh,
    //         ),
    //       ),
    //     )
    //         : model.iconData == null
    //         ? const SizedBox()
    //         : model.iconData is IconData
    //         ? Icon(
    //       model.iconData,
    //       color: Colors.white,
    //       size: 17 * spt,
    //     )
    //         : Center(
    //       child: Image.asset(model.iconData,
    //           width: 17 * sw, height: 17 * sw),
    //     ),
    //   ),
    //   title: Text(
    //     model.name,
    //     style: TextStyle(fontSize: 15 * spt, color: Colors.black),
    //   ),
    //   contentPadding: EdgeInsets.all(0),
    //   subtitle: model.subtitle == null
    //       ? null
    //       : Text(
    //     model.subtitle ?? '',
    //     style: TextStyle(
    //         color: const Color(0Xff5B5C60), fontSize: 12 * spt),
    //   ),
    //   onTap: () {
    //     function?.call(model.name);
    //     //
    //   },
    // );
  }
}
